package com.dtx.datastruct.huffmancode;

public class huffmanCodeDemo {
    public static void main(String[] args) {

        HuffmanCode huffmanCode = new HuffmanCode();
        //测试压缩文件
//		String srcFile = "d://Uninstall.xml";
//		String dstFile = "d://Uninstall.zip";
//
//		zipFile(srcFile, dstFile);
//		System.out.println("压缩文件ok~~");


        //测试解压文件
        String zipFile = "d://Uninstall.zip";
        String dstFile = "d://Uninstall2.xml";
        huffmanCode.unZipFile(zipFile, dstFile);
        System.out.println("解压成功!");

		/*
		String content = "i like like like java do you like a java";
		byte[] contentBytes = content.getBytes();
		System.out.println(contentBytes.length); //40

		byte[] huffmanCodesBytes= huffmanZip(contentBytes);
		System.out.println("压缩后的结果是:" + Arrays.toString(huffmanCodesBytes) + " 长度= " + huffmanCodesBytes.length);


		//测试一把byteToBitString方法
		//System.out.println(byteToBitString((byte)1));
		byte[] sourceBytes = decode(huffmanCodes, huffmanCodesBytes);

		System.out.println("原来的字符串=" + new String(sourceBytes)); // "i like like like java do you like a java"
		*/



        //如何将 数据进行解压(解码)
        //分步过程
		/*
		List<Node> nodes = getNodes(contentBytes);
		System.out.println("nodes=" + nodes);

		//测试一把，创建的赫夫曼树
		System.out.println("赫夫曼树");
		Node huffmanTreeRoot = createHuffmanTree(nodes);
		System.out.println("前序遍历");
		huffmanTreeRoot.preOrder();

		//测试一把是否生成了对应的赫夫曼编码
		Map<Byte, String> huffmanCodes = getCodes(huffmanTreeRoot);
		System.out.println("~生成的赫夫曼编码表= " + huffmanCodes);

		//测试
		byte[] huffmanCodeBytes = zip(contentBytes, huffmanCodes);
		System.out.println("huffmanCodeBytes=" + Arrays.toString(huffmanCodeBytes));//17

		//发送huffmanCodeBytes 数组 */


    }
}
